<include file="Public/min-header"/>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <style>#search-form > .form-group{margin-left: 10px;}</style>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 店铺渠道列表</h3>
                </div>
                <div class="panel-body">
                    <div class="navbar navbar-default">
                        <form action="" id="search-form2" class="navbar-form form-inline" method="post" onsubmit="return false">
                            <div class="form-group">
                                <label class="control-label">关键词</label>
                                <div class="input-group">
                                    <input type="text" name="key_word" value="" placeholder="请输入店铺名称关键词" id="input-shop-name" class="form-control">
                                </div>
                            </div>
                            <!--排序规则-->
                            <input type="hidden" name="orderby1" value="goods_id" />
                            <input type="hidden" name="orderby2" value="desc" />
                            <button type="submit"  id="shop_name" class="btn btn-primary" data-toggle='tooltip'data-original-title="筛选"><i class="fa fa-search"></i> 筛选</button>
                        </form>
                    </div>
                    <div id="ajax_return">
                        <form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <td class="text-center">
                                            <a href="#">id</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">店铺名称</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">店铺头像</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">联系人</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">联系电话</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">店铺所在省市</a>
                                        </td>
                                        <td class="text-left">
                                            <a href="#">店铺所在街道</a>
                                        </td>
                                        <td class="text-center">操作</td>
                                    </tr>
                                    </thead>
                                    <tbody id="box">
                                    <foreach name='shop_data' item='v'>

                                        <tr>

                                            <td class="text-right">{$v.id}</td>
                                            <td class="text-left">{$v.shop_name}</td>
                                            <td class="text-left"><img width="100px" height="100px" src="{$v.shop_head_img}" alt=""/></td>
                                            <td class="text-left">{$v.shop_user}</td>
                                            <td class="text-left">{$v.shop_tel}</td>
                                            <td class="text-left">{$v.shop_address_city}</td>
                                            <td class="text-left">{$v.shop_address_street}</td>

                                            <td class="text-center">
                                                <a href="javascript:update_shop_goods('{$v["id"]}', '{$goods_id}');" >添加</a>
                                            </td>
                                        </tr>
                                    </foreach>

                                    </tbody>
                                </table>
                            </div>
                            <input type="hidden" name="__hash__" value="00ea0d70ce1e0760a8bf5d90b5e30971_08363ccf4ed4c12cc7ec489900643f53" />
                            <div class="dataTables_paginate paging_simple_numbers" style="margin-left: 42%;">
                                <ul class="pagination">
                                    <li class="paginate_button"><a class="num" data-p="1" href="javascript:void(0)">首页</a></li>
                                    <li class="paginate_button"><a class="num" data-p="{$last}" href="javascript:void(0)">上一页</a></li>
                                    <li class="paginate_button"><a class="num" data-p="{$next}" href="javascript:void(0)">下一页</a></li>
                                    <li class="paginate_button"><a class="num" data-p="{$total_page}" href="javascript:void(0)">尾页</a></li>
                                    <li style="margin-left: 2rem;">当前为第{$p}页</li>
                                    <li style="margin-left: 2rem;">共{$total_page}页</li>

                                </ul>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script>

    $(document).on('click','#jinyong',function(){
        var id=$(this).attr('val');
        update_shop_status(id,0);
    });

    //修改店铺状态
    function update_shop_goods(shop_id, goods_id){
            $.ajax({
                url: "/index.php?m=Admin&c=ShopGoods&a=addEditShopGoods",
                type: "post",
                data: {shop_id: shop_id, goods_id: goods_id},
                dataType: "json",
                success: function (msg) {
                    console.log(msg);
                    if (msg.status != 1) {
                        alert('操作失败');
                    } else {
                        alert('操作成功');
                        window.location.href = msg.data.url;
                    }
                }
            });

    }


    $(document).on('click','#shop_name',function() {
        var shop_type=$('#shop_type').val();
        var shop_name=$('#input-shop-name').val();
        shop_list_search(shop_type,shop_name);
    });
    $("#shop_type").change(function(){
        var shop_type=$('#shop_type').val();
        var shop_name=$('#input-shop-name').val();
        shop_list_search(shop_type,shop_name);
    });


    function shop_list_search(shop_type,shop_name,p){
        $.ajax({
            url:"/index.php?m=Admin&c=Shop&a=shop_list_search",
            type:"post",
            data:{shop_type:shop_type,shop_name:shop_name,p:p},
            dataType:"json",
            success: function(msg) {
                if(msg.result ==400 || msg.result=='400'){
                    $('#box').html('<tr>没有找到你搜索的店铺</tr>');
                }else {
                    var content="";
                    $.each(msg.data.shop_data,function(k,v){
                        var address="";
                        if(v.license_address_city){
                            address+=v.license_address_city;
                        }
                        if(v.license_address_street){
                            address+=v.license_address_street;
                        }

                        content+='<tr>';
                        content+='<td class="text-center">';
                        content+='<input type="hidden" name="shipping_code[]" value="flat.flat">';
                        content+='</td>';
                        content+='<td class="text-right">'+v.id+'</td>';
                        content+='<td class="text-right">'+v.user_id+'</td>';
                        content+='<td class="text-left">'+v.shop_name+'</td>';
                        content+='<td class="text-left"><img width="100px" height="100px" src="'+v.shop_head_img+'" alt=""/></td>';
                        content+='<td class="text-left">'+ v.license_name+'</td>';
                        content+='<td class="text-left">'+address+'</td>';
                        content+='<td class="text-left"><img width="100px" height="100px" src="'+v.license_img+'" alt=""/></td>';
                        content+='<td class="text-left">'+v.shop_user+'</td>';
                        content+='<td class="text-left">'+v.shop_tel+'</td>';
                        content+='<td class="text-left">'+v.shop_address_city+'</td>';
                        content+='<td class="text-left">'+v.shop_address_street+'</td>';
                        // content+='<td class="text-left">'+v.shop_type_name+'</td>';
                        // content+='<td class="text-left">'+v.shop_bond+'</td>';
                        content+='<td class="text-left">'+v.shop_intro+'</td>';
                        content+='<td class="text-center">';
                        content+='审核通过';
                        content+='</td>';
                        content+='<td class="text-center">';
                        content+='<a href="{:U("Shop/update_shop",array("id"=>'+v.id+'))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="编辑">编辑</a>';
                        content+='<a href="#" id="jinyong" val="'+ v.id+'" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="禁用">禁用</a>';
                        content+='</td>';
                        content+='</tr>';
                    });
                    $('#box').html(content);
                    var str="";
                    str+='<li class="paginate_button"><a class="num" data-p="1" href="javascript:void(0)">首页</a></li>';
                    str+='<li class="paginate_button"><a class="num" href="javascript:void(0)" data-p="'+msg.data.last+'" >上一页</a></li>';
                    str+='<li class="paginate_button"><a class="num" href="javascript:void(0)" data-p='+msg.data.next+' >下一页</a></li>';
                    str+='<li class="paginate_button"><a class="num" href="javascript:void(0)" data-p='+msg.data.total_page+'>尾页</a></li>';
                    str+='<li style="margin-left: 2rem;">当前为第'+msg.data.p+'页</li>';
                    str+='<li style="margin-left: 2rem;">共'+msg.data.total_page+'页</li>';
                    $('.pagination').html(str);

                }

            }
        });
    }

    $(document).on('click','#del',function(){
        var id=$(this).attr('val');
        if(confirm('确定要删除吗?')){
            $.ajax({
                url:"/index.php?m=Admin&c=Shop&a=shop_del",
                type:"post",
                data:{id:id},
                dataType:"json",
                success: function(msg){
                    if(msg.result ==400 || msg.result=='400'){
                        alert('删除失败');
                    }else {
                        alert('删除成功');
                        window.location.href="";
                    }
                }
            });
        }

        return false;
    });

</script>
</body>
</html>